<template>
	<view class="modular">
		<view class="headerBox">
			<view class="header">
				<view class="information">
					<view>
						<view><text>会员</text>：{{data.userName}} </view>
						<view><text>填写日期</text>：{{data.fillFormDate}}</view>
					</view>
					<view>
						<view><text>性别</text>：{{userInfo.sex && userInfo.sex == 1 ? '男' : '女' || ''}} </view>
						<view><text>年龄</text>：{{userInfo && userInfo.age}}</view>
					</view>
					<view>
						<view><text>评估人</text>：{{data.healthName}}</view>
						<view><text>评估日期</text>：{{data.modifiedDate ? data.modifiedDate : data.createdDate}}</view>
					</view>
				</view>
			</view>
			
			<view class="connectBox" v-show="!searchBarFixed">
				<image src="@/static/img/healthStatus/connect@2x.png"></image>
				<image src="@/static/img/healthStatus/connect@2x.png"></image>
			</view>
		</view>
		<view class="mainContent">
			<view class="specific">
				<image src="@/static/img/healthStatus/screen.png" class="title"></image>
				<view class="single" v-for="(item,index) in psychologyQuestion[0] && psychologyQuestion[0].adTopicsRepliesEntityList" :key="index">
					<image src="@/static/img/healthStatus/questionIcon@2x.png"></image>
					<view>
						<view class="question">{{item.name}}</view>
						<view class="answer">
							{{questionData[index] && questionData[index].setvalue || '未选择'}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="questionDetail">
			<view class="specific">			
				<image src="@/static/img/healthStatus/questionnarDetail.png" class="title"></image>
				<view class="limit">在过去的两周内，有多少时候您受到以下问题困扰</view>
				<view class="single" v-for="(item,index) in psychologyQuestion[1] && psychologyQuestion[1].adTopicsRepliesEntityList" :key="index">
					<image src="@/static/img/healthStatus/questionIcon@2x.png"></image>
					<view>
						<view class="question">{{item.name}}</view>
						<view class="answer">
							{{ questionData1[index] && questionData1[index].setvalue || '未选择'}}
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {age,distance} from '@/static/js/filter.js'
	export default{
		data() {
			return {
				psychologyQuestion:[],
				data:{},
				answer: [],
				userInfo: {},
				questionData1:{},
				questionData:{},
				searchBarFixed: false
			}
		},
		onLoad(option) {
			if(option.id) {
				this.$api.getUserInfo().then((res) => {
					if(res.data.returnCode == 200) {
						this.userInfo = res.data && res.data.result
					}
				})
				this.question().then((reponse) => {
					this.$api.psychologyQuestionInfo(option.id).then((res) => {
						if(res.data.returnCode == 200) {
							this.data = res.data.result.newAppMentalHealthAssessmentEntity;
							this.answer = res.data.result.newUserTopicsEntities;
							this.questionData1 =  this.psychologyQuestion[1].adTopicsRepliesEntityList.map((a) => {
								this.answer.map((b) => {
									if(a.id == b.titleId) {
										a.adTopicsRepliesEntityList.map((c) => {
											if(c.elections == b.userOption) {
												c.checked = true;
												a.setvalue = c.value;
											}
										})
									}
								})
								return a
							})
							
							this.questionData =  this.psychologyQuestion[0].adTopicsRepliesEntityList.map((a) => {
								this.answer.map((b) => {
									if(a.id == b.titleId) {
										a.adTopicsRepliesEntityList.map((c) => {
											if(c.value == b.userValue) {
												c.checked = true;
												a.setvalue = c.value;
											}
										})
									}
								})
								return a
							})
						}
					})
				})
			}
		},
		onPageScroll() {
			this.searchBarFixed = this.distance('mainContent');
		},
		methods:{
			age,
			distance,
			question() {
				return new Promise((success,error)=>{
					this.$api.psychologyQuestion('ids=25&ids=26').then((res)=>{
						if(res){
							this.psychologyQuestion =  Object.keys(res.data.result).map((a) => {
								const aData = res.data.result[a].adTopicsRepliesEntityList.map((b) => {
									b.adTopicsRepliesEntityList.map((c) => {
										c.checked = false;
										return b
									})
									return b
								})
								return res.data.result[a]
							})
							success(res.data.result)
						}else{
							error('')
						}
					})
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import '@/static/css/healthStatus/toView.scss';
</style>
